package customer

import (
	"context"
	"encoding/json"
	"group-card/common/response"
	"group-card/rpc/sys/sysclient"

	"group-card/api/internal/svc"
	"group-card/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CustomerDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCustomerDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CustomerDeleteLogic {
	return &CustomerDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CustomerDeleteLogic) CustomerDelete(req *types.DeleteCustomerRequest) (resp *types.CustomerResponse, err error) {
	_, err = l.svcCtx.Sys.CustomerDelete(l.ctx, &sysclient.CustomerDeleteRequest{
		Id: req.Id,
	})

	if err != nil {
		reqStr, _ := json.Marshal(req)
		logx.WithContext(l.ctx).Errorf("删除集团客户失败,参数:%s,异常:%s", reqStr, err.Error())
		return &types.CustomerResponse{Code: response.ErrCode, Message: "删除集团客户失败"}, nil
	}

	return &types.CustomerResponse{
		Code:    response.SuccessCode,
		Message: "删除集团客户成功",
	}, nil

}
